<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>用户管理</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <link href="../../css/mine.css" type="text/css" rel="stylesheet">
    </head>

    <body>

        <div class="div_head">
            <span>
                <span style="float:left">当前位置是：-》资源管理》用户管理</span>
                <span style="float:right;margin-right: 8px;font-weight: bold">
                    <a style="text-decoration: none" href="${pageContext.request.contextPath}/sys/list">【返回】</a>
                </span>
            </span>
        </div>
        <div></div>

        <div style="font-size: 13px;margin: 10px 5px">
            <form action=""  id="formData" >
                <input type="hidden" name="id" value="${employee.id}"/>
                <table border="1" width="100%" class="table_a">
                    <tr>
                        <td width="120px;">用户编号<span style="color:red">*</span>：</td>
                        <td><input type="text" name="employeeNum" value="${employee.employeeNum}" /></td>
                    </tr>
                    <tr>
                        <td>登录账号<span style="color:red">*</span>：</td>
                        <td>
                            <input type="text" name="loginName" value="${employee.loginName}" />
                        </td>
                    </tr>

                    <tr>
                        <td>用户姓名<span style="color:red">*</span>：</td>
                        <td>
                            <input type="text" name="userName" value="${employee.userName}" /></td>
                    </tr>
                    <tr>
                        <td>密码<span style="color:red">*</span>：</td>
                        <td>
                            <input type="password"  name="loginPassword" value="${employee.loginPassword}" />
                        </td>
                    </tr>
                    <tr>
                        <td>所属职位<span style="color:red">*</span>：</td>
                        <td>
                            <select id="role" name="roleId">
                                <option value="0">请选择</option>
                                <c:forEach var="r" items="${roleList}">
                                    <option <c:if test="${r.roleId==employee.roleId}">selected</c:if>  value="${r.roleId}">${r.roleName}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>


                    <tr>
                        <td>所属部门<span style="color:red">*</span>：</td>
                        <td>
                            <select name="deptId" id="selects">
                                <option value="0">请选择</option>
                                <c:forEach var="i" items="${deptList}">
                                    <option <c:if test="${i.deptId==employee.deptId}">selected</c:if> value="${i.deptId}">${i.deptName}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td>身份证<span style="color:red">*</span>：</td>
                        <td>
                            <input type="text" name="idCaid" value="${employee.idCaid}" />
                        </td>
                    </tr>

                    <tr>
                        <td>联系电话<span style="color:red">*</span>：</td>
                        <td>
                            <input type="text" name="telphone" value="${employee.telphone}"/>
                        </td>
                    </tr>

                    <tr>
                        <td>邮箱<span style="color:red">*</span>：</td>
                        <td>
                            <input type="text" name="email" value="${employee.email}" />
                        </td>
                    </tr>

                    <tr>
                        <td>联系地址：</td>
                        <td>
                            <input type="text" name="address" value="${employee.address}" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <input type="button" id="submit" value="修改">
                            <input type="button" onclick="history.back()" value="返回">
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script>
    $("#submit").click(function () {
        var formData = $("#formData").serialize();
        $.post(
            "${pageContext.request.contextPath}/sys/updated",
            formData,
            function (result) {
                if(result.code==0){
                    alert("修改成功");
                    location.href="${pageContext.request.contextPath}/sys/list"
                }else{
                    alert(result.msg)
                }
            },
            "json"
        )
    });
    $("#selects").change(function () {
        var data= $(this).val();
        if(data==0){
            alert("请选择部门");
            return;
        }
        $.getJSON(
            "${pageContext.request.contextPath}/sys/roles",
            {deptId:data},
            function (result) {
                $("#role")[0].length=0;//让下拉框的长度为0
                $("#role")[0].add(new Option("请选择","0"));
                for(var i=0;i<result.data.length;i++){
                    $("#role")[0].add(new Option(result.data[i].roleName,result.data[i].roleId));//Option(显示到标签对中的值,value值)
                }
            }
        )
    });

</script>
</html>